Sprite Bytes are small tutorials that address a single method to be used with sprites in Liberty BASIC.
Using images more than once.
In the last Sprite Byte, we discussed the way to make a sprite cycle through it's image list. The example used four smiley-face images. It loaded one bitmap for each sprite image. We can go on doing that, but it is also possible to uses loaded bitmaps multiple times.
Using the same image for multiple sprites.
We can load a bitmap one time, and use it for as many sprites as we'd like. This allows us to create a whole fleet of alien ships with just one sprite. Here's some sample code that loads a single image, but uses it for three sprites.
loadbmp "ship","myship.bmp" #win "addsprite alien1 ship" #win "addsprite alien2 ship" #win "addsprite alien3 ship" #win "spritexy alien1 200 30" #win "spritexy alien2 10 130" #win "spritexy alien3 500 320" #win "drawsprites"
We can use LOADBMP for multiple images, and use all of them on multiple sprites, like this:
loadbmp "ship","myship.bmp" loadbmp "ship2","myship2.bmp" #win "addsprite alien1 ship ship2" #win "addsprite alien2 ship2 ship2" #win "addsprite alien3 ship ship" #win "spritexy alien1 200 30" #win "spritexy alien2 10 130" #win "spritexy alien3 500 320" #win "cyclesprite alien1 1" #win "cyclesprite alien2 1" #win "cyclesprite alien3 -1" #win "drawsprites"
Each of the alien sprites will cycle through both images. Notice that we didn't list them in the same order for all of the alien ships, and we didn't cyle them all in the same direction. The image list for sprites is very versatile!
Using the same image more than once in a single sprite.
Here are four images of a flying bug.

The bugs are added to the program like this:
loadbmp "bug1", "bug1.bmp"
loadbmp "bug2", "bug2.bmp"
loadbmp "bug3", "bug3.bmp"
loadbmp "bug4", "bug4.bmp"
'add a sprite
#wg "addsprite bug bug1 bug2 bug3 bug4"
The wings are in a different position in each image. If the four images are added to a sprite when it is created, the bug will fly with a jerky motion, because when it gets to the bottom wing image, it jumps back to the top wing image, with no middle wings in between.
We could make two more images, load all six with LOADBMP , and add six images to the sprite instead of four.
We don't really need to do that, though. Notice that the two "middle wing" images are duplicated. We only need to use LOADBMP on each of them one time. We can add a loaded bitmap to the same sprite image list multiple times, like this:
#wg "addsprite insect bug1 bug2 bug3 bug4 bug3 bug2"
In the code above, bug2 and bug3 were used twice in the sprite list. The cycling sprite that uses this image list looks like this:

DEMO
Look for the file "spritebug.bas" in the zipped archive of this newsletter. The sprite bitmaps are also included. The demo adds two sprites. The first sprite uses each of the four bug images just one time. The other sprite uses bug2 and bug3 twice, so that the flying motion is smoother.
For a challenge, try adding more insect sprites to the demo, and change the list of images and the way they cycle to see how it affects them. Change the timer interval, too.